<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	//设置无缓存
	response.addHeader("Progma","no-cache");
	response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires",0);
	response.setHeader("Pragma", "no-cache");   
	response.setHeader("Cache-Control", "no-store");  
	response.setHeader("Cache-Control", "must-revalidate");
%>

<!DOCTYPE html>
<html>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8">
	
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/easyui/themes/icon.css">
	
	<script type="text/javascript" src="<%=basePath %>js/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/easyui/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/timeformat/timeformattool.js"></script>
	<script language="javascript" type="text/javascript" src="<%=basePath %>js/My97DatePicker/WdatePicker.js"></script>
	<link rel="stylesheet" type="text/css" href="<%=basePath %>js/My97DatePicker/skin/WdatePicker.css">	
	
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/common_main.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/main_main.css" />
	
	<link rel="stylesheet" href="<%=basePath %>css/jqueryvalidation/screen.css" type="text/css"></link>
	<script type="text/javascript" src="<%=basePath %>js/jqueryvalidation/jquery.validate.js"></script>、
	<script type="text/javascript" src="<%=basePath %>js/ajaxfileupload.js"></script>
	
<body>
<div id="areaForm" class="easyui-panel" title="新建项目申报" style="width:auto;padding:30px 60px;height:auto">
<input type="hidden" id="isModify" value="${not empty projectapply ? 'yes':'no' }"></input>
<input type="hidden" id="ischakan" value="${ismodify}"></input>
<form id="submitform" enctype="multipart/form-data">
		<div class="config-items">
			 <div class="result-content">
					<table class="insert-tab" width="100%">
							  <tbody>
<tr>
							      <th width="25%">申报单位</th>
							      <td width="75%">
							      	<input type="hidden" id="id" value="${projectapply.id}"></input>
											<c:forEach items="${departments}" var="item">
												<c:choose>
													<c:when test="${sysuser.department == item.id }">
														<%-- <option value="${item.id}" selected="selected">${item.name}</option> --%>
														<input id="areaid" name="areaid" type="text" style="width:50%" value="${item.name }" disabled="disabled"/>
													</c:when>
													<c:otherwise>
														<%-- <option value="${item.id}">${item.name}</option> --%>
													</c:otherwise>
												</c:choose>
											</c:forEach>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">实验室名称</th>
							      <td width="75%">
										<input id="labname" name="labname" type="text" style="width:50%" value="${projectapply.labname }" disabled="disabled"/>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">申报人</th>
							      <td width="75%">
							      		
										<c:choose>
											<c:when test="${not empty projectapply == true}">
												<input id="username" name="username" type="text" style="width:50%" value="${sysuser.username }" disabled="disabled"/>
												<%-- <input id="username" name="username" type="text" style="width:50%" value="${sysuser.username }"/> --%>
											</c:when>
											<c:otherwise>
												<input id="username" name="username" type="text" style="width:50%" value="${sysuser.username }" disabled="disabled"/>
												<input type="hidden" id="userid" value="${sysuser.id}"></input>
											</c:otherwise>
										</c:choose>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">申报时间</th>
							      <td width="75%">
							      	<input id="applytime" name="applytime" type="text" style="width:50%" onfocus="new WdatePicker({startDate:'%y-%M-01',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" value="${projectapply.applytime }" disabled="disabled"/>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">申报经费</th>
							      <td width="75%">
							      	<input id="applymoney" name="applymoney" type="text" style="width:50%"  value="${projectapply.applymoney }" disabled="disabled"/>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">备注</th>
							      <td width="75%">
							      	<textarea id="remark" name="remark" rows="3"  style="width:50%" disabled="disabled">${projectapply.remark }</textarea>
							      </td>
							    </tr>

							    <tr>
							      <th width="25%">附件</th>
							      <td width="75%">
							      	<input id="attachmenttxt" name="attachmenttxt" type="text" style="width:25%" value="${projectapply.attachment }" readonly="readonly"/>
							      	<input id="attachment" name="attachment" type="file" style="width:25%" />
							      	<a id="download" href="<%=basePath %>project/download.do?file=">下载</a>
							      </td>
							    </tr>
							    
							    
							    
							    <tr>
							      <th width="25%">项目状态</th>
							      <td width="75%">
							      		<select style="width:200px" name="projectstateid" id="projectstateid">
											<c:forEach items="${projectstates}" var="item">
												<c:choose>
													<c:when test="${projectapply.projectstateid == item.id }">
														<option value="${item.id}" selected="selected">${item.name}</option>
													</c:when>
													<c:otherwise>
														<option value="${item.id}">${item.name}</option>
													</c:otherwise>
												</c:choose>
											</c:forEach>
										</select>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">资金来源</th>
							      <td width="75%">
							      		<select style="width:200px" name="moneysourceid" id="moneysourceid">
											<c:forEach items="${moneysources}" var="item">
												<c:choose>
													<c:when test="${projectapply.moneysourceid == item.id }">
														<option value="${item.id}" selected="selected">${item.name}</option>
													</c:when>
													<c:otherwise>
														<option value="${item.id}">${item.name}</option>
													</c:otherwise>
												</c:choose>
											</c:forEach>
										</select>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">项目等级</th>
							      <td width="75%">
							      	<input id="projectlevel" name="projectlevel" type="text" style="width:50%" value="${projectapply.projectlevel }"/>
							      </td>
							    </tr>
							    <tr>
							      <th width="25%">项目类别信息</th>
							      <td width="75%">
							      	<input id="projectcategory" name="projectcategory" type="text" style="width:50%" value="${projectapply.projectcategory }"/>
							      </td>
							    </tr>
							    
							    
							    
							    
							    <tr>
							      <th width="25%"></th>
							      <td width="75%">
										<span>
											
											<input class="btn" name="seachpoint" id="seachpoint" value="提交" type="submit" style="width:25%;height:30px" />
											<input class="btn" name="returnback" id="returnback" value="返回" type="button" style="width:25%;height:30px" onclick="javascript:history.go(-1)"/>
											
											<!-- <input class="submit" type="submit" value="提交 "></input> -->
										</span>							      	
							      </td>
							    </tr>
							  </tbody>
					</table>			 	
			 </div>
        </div>
</form>
</div>
</body>
</html>

<script type="text/javascript">
$(document).ready(function(){
	if($("#applytime").val() != ""){
		var data = new Date($("#applytime").val()).format("yyyy-MM-dd");
		$("#applytime").val(data) ;
	}

	if($("#ischakan").val() == "chakan"){
		$("#seachpoint").hide();
	}
	if($("#attachmenttxt").val() == ""){
		$("#attachmenttxt").hide();
		$("#download").hide();
	}else{
		$("#download").attr("href",$("#download").attr("href")+encodeURI(encodeURI($("#attachmenttxt").val())));
	}
	$.validator.setDefaults({
		submitHandler: function() {
			var data = serializeForm($("#submitform"));
			delete data["username"];  
			delete data["areaid"];  
			delete data["seachpoint"];
			delete data["returnback"];
			delete data["download"];
			data["userid"] = $("#userid").val();

			
			var postUrl = "";
			if($("#isModify").val()=="yes"){
				data["id"] = $("#id").val();
				postUrl = getContextPath()+"/project/updateapply.do";
			}else{
				postUrl = getContextPath()+"/project/addapply.do";
			}
			var postdata = JSON.stringify(data);
			postUrl = postUrl + "?data="+encodeURI(encodeURI(postdata.toString()));
			$.ajaxFileUpload({  
	            url:postUrl,  
	            secureuri:false,  
	            fileElementId:'attachment',//file标签的id  
	            dataType: 'json',//返回数据的类型  
	            data:postdata,//一同上传的数据  
	            success: function (data, status) {  
					if(data.key == "pass"){
						if($("#isModify").val()=="yes"){
							$.messager.alert("提示","你已经修改成功","info");
							$( "#submitform" ).validate().resetForm();
						}else{
							$.messager.alert("提示","你已经添加成功","info");
							$( "#submitform" ).validate().resetForm();
						}
					}
	            },  
	            error: function (data, status, e) {  
	                alert(e);  
	            }  
        	});
			
		},

	});
	
	$("#submitform").validate({
		rules: {
			sewageid:"required",
			deviceid: {
				required:true
			}
		},
		messages: {
			sewageid:"请选择一个地区",
			deviceid: {
				required: "请选择一个设备"
			}
		}
	});	
	
});

function serializeForm(form)
{
    var obj = {};
    $.each(form.serializeArray(), function (index)
    {
        if (obj[this['name']])
        {
            obj[this['name']] = obj[this['name']] + ',' + this['value'];
        }
        else
        {
            obj[this['name']] = this['value'];
        }
    }
    );
    return obj;
}
function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}
</script>